package com.railway.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class SelectContactServlet
 */
/**
 * 用于查询乘车人
 * @author 33676
 *
 */
@WebServlet("/SelectContactServlet.do")
public class SelectContactServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("Utf-8");
		int user_id = 0;
		String user_name="";
		
		
		if(request.getParameter("user_id") != null && !"".equals(request.getParameter("user_id"))) {
			user_id = Integer.parseInt(request.getParameter("user_id"));
		}
		
		if(request.getParameter("user_name") != null && !"".equals(request.getParameter("user_name"))) {
			user_name = request.getParameter("user_name");
		}
		
		UserService user = new UserServiceImpl();
		if(request.getParameter("user_name") != null && !"".equals(request.getParameter("user_name"))) {
			JSONUtil.responJSOn(response, user.selectContactByIdAndName(user_id, user_name));
		}else {
			JSONUtil.responJSOn(response, user.selectContact(user_id));
		}
	}

}
